/*
 * dialog.cpp
 *
 *  Created on: 21.05.2010
 *      Author: 123
 */
#include "dialog.h"
#include "oslib/oslib.h"
#include "Colors.h"
extern "C" {
#include "pgeFont.h"
}
extern pgeFont *nash;
boxrun::boxrun(char *string, float speed) {
	this->string = string;
	this->speed = speed;
	this->time = 0;
	this->length = strlen(string);
	this->pause = false;
	this->stop = false;
	this->pauseMenu = true;
	this->Amount = 0;
	this->SecondSpeed = speed;

}
;
void boxrun::drawbox() {
	if (this->pauseMenu) {
		int i;
		IsStop();

		if (!stop) {
			if (pause == false)
				this->time += speed;
			else
				oslDrawImageXY(dialogPause,410,220);
			if (pause && osl_keys->pressed.cross) {
				pause = false;
				if (i < (int) this->time)
					this->Amount = (int) this->time - ((int) this->time - i);
				else
					this->Amount = (int) this->time;
				this->length -= this->time;
				this->time = 0;
				this->speed = this->SecondSpeed;
				osl_keys->pressed.cross = 0;
			}
			if (osl_keys->pressed.cross && pause == false) {
				this->speed = 10;

			}

		} else if (osl_keys->pressed.cross && stop)
			this->pauseMenu = false;
		else
			oslDrawImageXY(dialogPause,410,220);
		osl_keys->pressed.cross = 0;
		oslDrawFillRect(0, 230, 480, 272, RGB(242, 101, 34));
		int x = 0;
		int y = 0;

		pgeFontActivate(nash);

		for (i = 0; i < (unsigned int) this->time; i++) {
			Glyphg *glyph = nash->glyph + nash->map[this->string[i
					+ this->Amount] & 0xff];

			if (x + glyph->advance > 480) {
				y += 10;
				x = 0;
			}
			if (y > 30) {
				pause = true;
				break;

			}

			pgeFontPrintf(nash, x, 240 + y, BLACK, "%c",
					this->string[i + this->Amount]);
			x += glyph->advance;

		}

	}
}
;
void boxrun::SetSpeedAndString(char *string, float speed) {
	this->string = string;
	this->speed = speed;
	this->time = 0;
	this->length = strlen(string);
	this->pause = false;
	this->stop = false;
	this->pauseMenu = true;
	this->Amount = 0;
	this->SecondSpeed = speed;

}
;
boxrun * Dialog;
